<!DOCTYPE html>
<html>
  
<!-- Mirrored from www.dba.cn/book/electron/ZaiZhuJinChengNeiKeYongDeMoKuai/ELECTRONMENUMoKuai.html by HTTrack Website Copier/3.x [XR&CO'2014], Sun, 20 Mar 2022 10:24:10 GMT -->
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Electron menu 模块 - Electron中文手册</title>
    <link rel="stylesheet" type="text/css" href="../../skins/cms/css/min-easyui.css">
    <link rel="stylesheet" type="text/css" href="../../skins/cms/css/book.css">
    <script type="text/javascript" src="../../js/jquery.min.js"></script>
    <script type="text/javascript" src="../../skins/cms/js/m-easyui.js"></script>
    <script type="text/javascript" src="../../skins/cms/js/prettify.js"></script>
  </head>
  <body class="easyui-layout" style="text-align:left">
    <div region="north" border="false" class="group wrap header" style="height:66px;font-size:100%">
      <div class="header">
        <div class="navigation-toggle" data-tools="navigation-toggle" data-target="#navbar-1">
          <span>Electron中文手册</span>
        </div>
        <div id="elogo" class="navbar navbar-left">
          <ul>
            <li>
              <h1><a href="../index.html">Electron中文手册</a></h1>
            </li>
          </ul>
        </div>
      <div style="clear:both"></div>
    </div>
   </div>
    <div region="west" split="true" data-options="collapsedSize:0,hideExpandTool:true" title="文档目录" style="width:20%;min-width:300px;padding:5px;display:none;">
        
      <ul class="easyui-tree"> 
        <li iconcls="icon-base"><span>Electron 教程</span><ul><li iconcls="icon-gears"><a href="../ELECTRONJiaoCheng/ELECTRONJiaoChengJianJie.html">Electron 教程简介</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONKuaiSuRuMen.html">Electron 快速入门</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONZhuoMianHuanJingJiCheng.html">Electron 桌面环境集成</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONZaiXianLiXianShiJianTanCe.html">Electron 在线/离线事件探测</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONJinCheng.html">Electron 进程</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONZhiChiDeCHROMEMingLingXingKaiGuan.html">Electron 支持的 Chrome 命令行开关</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONHuanJingBianLiang.html">Electron 环境变量</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONZhiChiDePingTai.html">Electron 支持的平台</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONYingYongBuShu.html">Electron 应用部署</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONXiangMACAPPSTOREYingYongTiJiaoXiangDao.html">Electron 向Mac App Store 应用提交向导</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONYingYongDaBao.html">Electron 应用打包</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONShiYongYuanShengMoKuai.html">Electron 使用原生模块</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONZhuJinChengDiaoShi.html">Electron 主进程调试</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONShiYongSELENIUMHeWEBDRIVER.html">Electron 使用 Selenium 和 WebDriver</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONDEVTOOLSKuoZhan.html">Electron DevTools扩展</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONShiYongPEPPERFLASHChaJian.html">Electron 使用 Pepper Flash 插件</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONShiYongWIDEVINECDMChaJian.html">Electron 使用 Widevine CDM 插件</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONShuYuBiao.html">Electron 术语表</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONLiPingRan.html">Electron 离屏渲染</a></li><li iconcls="icon-gears"><a  href="../ELECTRONJiaoCheng/ELECTRONJiaoHuShiJieShiQiREPL.html">Electron 交互式解释器 (REPL)</a></li></ul></li><li iconcls="icon-base"><span>Electron API</span><ul><li iconcls="icon-gears"><a  href="../ELECTRONAPI/ELECTRONDOMFILEDuiXiang.html">Electron DOM File对象</a></li><li iconcls="icon-gears"><a  href="../ELECTRONAPI/ELECTRONDOMWEBVIEWBiaoQian.html">Electron DOM <webview> 标签</a></li><li iconcls="icon-gears"><a  href="../ELECTRONAPI/ELECTRONWINDOWOPENHanShu.html">Electron window.open 函数</a></li></ul></li><li iconcls="icon-base"><span>在主进程内可用的模块</span><ul><li iconcls="icon-gears"><a  href="ELECTRONAPPMoKuai.html">Electron app 模块</a></li><li iconcls="icon-gears"><a  href="ELECTRONAUTOUPDATERMoKuai.html">Electron autoUpdater 模块</a></li><li iconcls="icon-gears"><a  href="ELECTRONBROWSERWINDOWMoKuai.html">Electron BrowserWindow 模块</a></li><li iconcls="icon-gears"><a  href="ELECTRONCONTENTTRACINGMoKuai.html">Electron contentTracing 模块</a></li><li iconcls="icon-gears"><a  href="ELECTRONDIALOGMoKuai.html">Electron dialog 模块</a></li><li iconcls="icon-gears"><a  href="ELECTRONGLOBAL-SHORTCUTMoKuai.html">Electron global-shortcut 模块</a></li><li iconcls="icon-gears"><a  href="ELECTRONIPCMAINMoKuai.html">Electron ipcMain 模块</a></li><li iconcls="icon-gears"><a  href="ELECTRONMENUMoKuai.html">Electron menu 模块</a></li><li iconcls="icon-gears"><a  href="ELECTRONMENUITEMMoKuai.html">Electron MenuItem 模块</a></li><li iconcls="icon-gears"><a  href="ELECTRONPOWERMONITORMoKuai.html">Electron powerMonitor 模块</a></li><li iconcls="icon-gears"><a  href="ELECTRONPOWERSAVEBLOCKERMoKuai.html">Electron powerSaveBlocker 模块</a></li><li iconcls="icon-gears"><a  href="ELECTRONPROTOCOLMoKuai.html">Electron protocol 模块</a></li><li iconcls="icon-gears"><a  href="ELECTRONSESSIONMoKuai.html">Electron session 模块</a></li><li iconcls="icon-gears"><a  href="ELECTRONWEBCONTENTSMoKuai.html">Electron webContents 模块</a></li><li iconcls="icon-gears"><a  href="ELECTRONTRAYMoKuai.html">Electron Tray 模块</a></li><li iconcls="icon-gears"><a  href="ELECTRONLOCALES.html">Electron Locales</a></li></ul></li><li iconcls="icon-base"><span>在渲染进程（网页）内可用的模块</span><ul><li iconcls="icon-gears"><a  href="../ZaiRanJinChengWangYeNeiKeYongDeMoKuai/ELECTRONDESKTOPCAPTURERMoKuai.html">Electron desktopCapturer 模块</a></li><li iconcls="icon-gears"><a  href="../ZaiRanJinChengWangYeNeiKeYongDeMoKuai/ELECTRONIPCRENDERERMoKuai.html">Electron ipcRenderer 模块</a></li><li iconcls="icon-gears"><a  href="../ZaiRanJinChengWangYeNeiKeYongDeMoKuai/ELECTRONREMOTEMoKuai.html">Electron remote 模块</a></li><li iconcls="icon-gears"><a  href="../ZaiRanJinChengWangYeNeiKeYongDeMoKuai/ELECTRONWEBFRAMEMoKuai.html">Electron webFrame 模块</a></li></ul></li><li iconcls="icon-base"><span>两种进程都可用的模块</span><ul><li iconcls="icon-gears"><a  href="../LiangZhongJinChengDuKeYongDeMoKuai/ELECTRONCLIPBOARDMoKuai.html">Electron clipboard 模块</a></li><li iconcls="icon-gears"><a  href="../LiangZhongJinChengDuKeYongDeMoKuai/ELECTRONCRASHREPORTERMoKuai.html">Electron crashReporter 模块</a></li><li iconcls="icon-gears"><a  href="../LiangZhongJinChengDuKeYongDeMoKuai/ELECTRONNATIVEIMAGEMoKuai.html">Electron nativeImage 模块</a></li><li iconcls="icon-gears"><a  href="../LiangZhongJinChengDuKeYongDeMoKuai/ELECTRONSCREENMoKuai.html">Electron screen 模块</a></li><li iconcls="icon-gears"><a  href="../LiangZhongJinChengDuKeYongDeMoKuai/ELECTRONSHELLMoKuai.html">Electron shell 模块</a></li></ul></li><li iconcls="icon-base"><span>Electron 开发</span><ul><li iconcls="icon-gears"><a  href="../ELECTRONKaiFa/ELECTRONBianMaGuiFan.html">Electron 编码规范</a></li><li iconcls="icon-gears"><a  href="../ELECTRONKaiFa/ELECTRONYuanMaMuLuJieGou.html">Electron 源码目录结构</a></li><li iconcls="icon-gears"><a  href="../ELECTRONKaiFa/ELECTRONHeNWJSYuanMingNODE-WEBKITZaiJiShuShangDeChaYi.html">Electron 和 NW.js (原名 node-webkit) 在技术上的差异</a></li><li iconcls="icon-gears"><a  href="../ELECTRONKaiFa/ELECTRONGouJianXiTongGaiLan.html">Electron 构建系统概览</a></li><li iconcls="icon-gears"><a  href="../ELECTRONKaiFa/ELECTRONGouJianBuZhouOSX.html">Electron 构建步骤 (OS X)</a></li><li iconcls="icon-gears"><a  href="../ELECTRONKaiFa/ELECTRONGouJianBuZhouWINDOWS.html">Electron 构建步骤 (Windows)</a></li><li iconcls="icon-gears"><a  href="../ELECTRONKaiFa/ELECTRONGouJianBuZhouLINUX.html">Electron 构建步骤 (Linux)</a></li><li iconcls="icon-gears"><a  href="../ELECTRONKaiFa/ELECTRONZaiDiaoShiZhongShiYongSYMBOLSERVER.html">Electron 在调试中使用 Symbol Server</a></li><li iconcls="icon-gears"><a  href="../ELECTRONKaiFa/ELECTRONChangJianWenTi.html">Electron 常见问题</a></li><li iconcls="icon-gears"><a  href="../ELECTRONKaiFa/ELECTRONBanBenGuanLi.html">Electron 版本管理</a></li><li iconcls="icon-gears"><a  href="../ELECTRONKaiFa/ELECTRONWINDOWTiJiaoZhiNan.html">electron window 提交指南</a></li><li iconcls="icon-gears"><a  href="../ELECTRONKaiFa/ZiDongHuaChiXuJiChengXiTongCICeShi.html">自动化持续集成系统（CI）测试</a></li><li iconcls="icon-gears"><a  href="../ELECTRONKaiFa/ELECTRONWenDangFengGeZhiNan.html">Electron 文档风格指南</a></li></ul></li>
      </ul>
    
    </div>
    <div region="center">
      <div id="tt" class="easyui-tabs" fit="true" border="false" plain="true">
        <div title="Electron menu 模块 - Electron中文手册">  
            <div class="book-content">
              
      <div style="padding:8px;"> &gt; <a href="../index.html">Electron中文手册</a> &gt; Electron menu 模块</div>
      <div class="content"><p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>menu</code><span> </span>类可以用来创建原生菜单，它可用作应用菜单和<span> </span>context 菜单.</p>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>这个模块是一个主进程的模块，并且可以通过<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>remote</code><span> </span>模块给渲染进程调用.</p>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>每个菜单有一个或几个菜单项<span> </span><a href="MENUITEMS.html">menu items</a>，并且每个菜单项可以有子菜单.</p>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>下面这个例子是在网页(渲染进程)中通过<span> </span><a href="REMOTE.html">remote</a><span> </span>模块动态创建的菜单，并且右键显示:</p>
<pre style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; break-inside: avoid; direction: ltr; border: none; color: rgb(51, 51, 51); overflow: auto; word-wrap: normal; margin: 0px 0px 1.275em; padding: 0.85em 1em; background: rgb(247, 247, 247); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><code class="lang-html" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0px; margin: 0px; background: 0px 0px; display: inline; max-width: initial; overflow: initial; line-height: inherit; white-space: pre;'><span class="hljs-comment" >&lt;!-- index.html --&gt;</span>
<span class="hljs-tag" >&lt;<span class="hljs-title" >script</span>&gt;</span><span class="javascript" >
<span class="hljs-keyword" >const</span> remote = <span class="hljs-built_in" >require</span>(<span class="hljs-string" >'electron'</span>).remote;
<span class="hljs-keyword" >const</span> Menu = remote.Menu;
<span class="hljs-keyword" >const</span> MenuItem = remote.MenuItem;

<span class="hljs-keyword" >var</span> menu = <span class="hljs-keyword" >new</span> Menu();
menu.append(<span class="hljs-keyword" >new</span> MenuItem({ label: <span class="hljs-string" >'MenuItem1'</span>, click: <span class="hljs-function" ><span class="hljs-keyword" >function</span>(<span class="hljs-params" ></span>) </span>{ <span class="hljs-built_in" >console</span>.log(<span class="hljs-string" >'item 1 clicked'</span>); } }));
menu.append(<span class="hljs-keyword" >new</span> MenuItem({ type: <span class="hljs-string" >'separator'</span> }));
menu.append(<span class="hljs-keyword" >new</span> MenuItem({ label: <span class="hljs-string" >'MenuItem2'</span>, type: <span class="hljs-string" >'checkbox'</span>, checked: <span class="hljs-literal" >true</span> }));

<span class="hljs-built_in" >window</span>.addEventListener(<span class="hljs-string" >'contextmenu'</span>, <span class="hljs-function" ><span class="hljs-keyword" >function</span> (<span class="hljs-params" >e</span>) </span>{
  e.preventDefault();
  menu.popup(remote.getCurrentWindow());
}, <span class="hljs-literal" >false</span>);
</span><span class="hljs-tag" >&lt;/<span class="hljs-title" >script</span>&gt;</span>
</code></pre>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>例子，在渲染进程中使用模板api创建应用菜单:</p>
<pre style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; break-inside: avoid; direction: ltr; border: none; color: rgb(51, 51, 51); overflow: auto; word-wrap: normal; margin: 0px 0px 1.275em; padding: 0.85em 1em; background: rgb(247, 247, 247); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><code class="lang-javascript" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0px; margin: 0px; background: 0px 0px; display: inline; max-width: initial; overflow: initial; line-height: inherit; white-space: pre;'><span class="hljs-keyword" >var</span> template = [
  {
    label: <span class="hljs-string" >'Edit'</span>,
    submenu: [
      {
        label: <span class="hljs-string" >'Undo'</span>,
        accelerator: <span class="hljs-string" >'CmdOrCtrl+Z'</span>,
        role: <span class="hljs-string" >'undo'</span>
      },
      {
        label: <span class="hljs-string" >'Redo'</span>,
        accelerator: <span class="hljs-string" >'Shift+CmdOrCtrl+Z'</span>,
        role: <span class="hljs-string" >'redo'</span>
      },
      {
        type: <span class="hljs-string" >'separator'</span>
      },
      {
        label: <span class="hljs-string" >'Cut'</span>,
        accelerator: <span class="hljs-string" >'CmdOrCtrl+X'</span>,
        role: <span class="hljs-string" >'cut'</span>
      },
      {
        label: <span class="hljs-string" >'Copy'</span>,
        accelerator: <span class="hljs-string" >'CmdOrCtrl+C'</span>,
        role: <span class="hljs-string" >'copy'</span>
      },
      {
        label: <span class="hljs-string" >'Paste'</span>,
        accelerator: <span class="hljs-string" >'CmdOrCtrl+V'</span>,
        role: <span class="hljs-string" >'paste'</span>
      },
      {
        label: <span class="hljs-string" >'Select All'</span>,
        accelerator: <span class="hljs-string" >'CmdOrCtrl+A'</span>,
        role: <span class="hljs-string" >'selectall'</span>
      },
    ]
  },
  {
    label: <span class="hljs-string" >'View'</span>,
    submenu: [
      {
        label: <span class="hljs-string" >'Reload'</span>,
        accelerator: <span class="hljs-string" >'CmdOrCtrl+R'</span>,
        click: <span class="hljs-function" ><span class="hljs-keyword" >function</span>(<span class="hljs-params" >item, focusedWindow</span>) </span>{
          <span class="hljs-keyword" >if</span> (focusedWindow)
            focusedWindow.reload();
        }
      },
      {
        label: <span class="hljs-string" >'Toggle Full Screen'</span>,
        accelerator: (<span class="hljs-function" ><span class="hljs-keyword" >function</span>(<span class="hljs-params" ></span>) </span>{
          <span class="hljs-keyword" >if</span> (process.platform == <span class="hljs-string" >'darwin'</span>)
            <span class="hljs-keyword" >return</span> <span class="hljs-string" >'Ctrl+Command+F'</span>;
          <span class="hljs-keyword" >else</span>
            <span class="hljs-keyword" >return</span> <span class="hljs-string" >'F11'</span>;
        })(),
        click: <span class="hljs-function" ><span class="hljs-keyword" >function</span>(<span class="hljs-params" >item, focusedWindow</span>) </span>{
          <span class="hljs-keyword" >if</span> (focusedWindow)
            focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
        }
      },
      {
        label: <span class="hljs-string" >'Toggle Developer Tools'</span>,
        accelerator: (<span class="hljs-function" ><span class="hljs-keyword" >function</span>(<span class="hljs-params" ></span>) </span>{
          <span class="hljs-keyword" >if</span> (process.platform == <span class="hljs-string" >'darwin'</span>)
            <span class="hljs-keyword" >return</span> <span class="hljs-string" >'Alt+Command+I'</span>;
          <span class="hljs-keyword" >else</span>
            <span class="hljs-keyword" >return</span> <span class="hljs-string" >'Ctrl+Shift+I'</span>;
        })(),
        click: <span class="hljs-function" ><span class="hljs-keyword" >function</span>(<span class="hljs-params" >item, focusedWindow</span>) </span>{
          <span class="hljs-keyword" >if</span> (focusedWindow)
            focusedWindow.toggleDevTools();
        }
      },
    ]
  },
  {
    label: <span class="hljs-string" >'Window'</span>,
    role: <span class="hljs-string" >'window'</span>,
    submenu: [
      {
        label: <span class="hljs-string" >'Minimize'</span>,
        accelerator: <span class="hljs-string" >'CmdOrCtrl+M'</span>,
        role: <span class="hljs-string" >'minimize'</span>
      },
      {
        label: <span class="hljs-string" >'Close'</span>,
        accelerator: <span class="hljs-string" >'CmdOrCtrl+W'</span>,
        role: <span class="hljs-string" >'close'</span>
      },
    ]
  },
  {
    label: <span class="hljs-string" >'Help'</span>,
    role: <span class="hljs-string" >'help'</span>,
    submenu: [
      {
        label: <span class="hljs-string" >'Learn More'</span>,
        click: <span class="hljs-function" ><span class="hljs-keyword" >function</span>(<span class="hljs-params" ></span>) </span>{ <span class="hljs-built_in" >require</span>(<span class="hljs-string" >'electron'</span>).shell.openExternal(<span class="hljs-string" >'http://electron.atom.io'</span>) }
      },
    ]
  },
];

<span class="hljs-keyword" >if</span> (process.platform == <span class="hljs-string" >'darwin'</span>) {
  <span class="hljs-keyword" >var</span> name = <span class="hljs-built_in" >require</span>(<span class="hljs-string" >'electron'</span>).remote.app.getName();
  template.unshift({
    label: name,
    submenu: [
      {
        label: <span class="hljs-string" >'About '</span> + name,
        role: <span class="hljs-string" >'about'</span>
      },
      {
        type: <span class="hljs-string" >'separator'</span>
      },
      {
        label: <span class="hljs-string" >'Services'</span>,
        role: <span class="hljs-string" >'services'</span>,
        submenu: []
      },
      {
        type: <span class="hljs-string" >'separator'</span>
      },
      {
        label: <span class="hljs-string" >'Hide '</span> + name,
        accelerator: <span class="hljs-string" >'Command+H'</span>,
        role: <span class="hljs-string" >'hide'</span>
      },
      {
        label: <span class="hljs-string" >'Hide Others'</span>,
        accelerator: <span class="hljs-string" >'Command+Alt+H'</span>,
        role: <span class="hljs-string" >'hideothers'</span>
      },
      {
        label: <span class="hljs-string" >'Show All'</span>,
        role: <span class="hljs-string" >'unhide'</span>
      },
      {
        type: <span class="hljs-string" >'separator'</span>
      },
      {
        label: <span class="hljs-string" >'Quit'</span>,
        accelerator: <span class="hljs-string" >'Command+Q'</span>,
        click: <span class="hljs-function" ><span class="hljs-keyword" >function</span>(<span class="hljs-params" ></span>) </span>{ app.quit(); }
      },
    ]
  });
  <span class="hljs-comment" >// Window menu.</span>
  template[<span class="hljs-number" >3</span>].submenu.push(
    {
      type: <span class="hljs-string" >'separator'</span>
    },
    {
      label: <span class="hljs-string" >'Bring All to Front'</span>,
      role: <span class="hljs-string" >'front'</span>
    }
  );
}

<span class="hljs-keyword" >var</span> menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
</code></pre>
<h2 id="类-menu" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 1.75em; orphans: 3; widows: 3; break-after: avoid; margin-top: 1.275em; margin-bottom: 0.85em; font-weight: 700; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>类: Menu</h2>
<h3 id="new-menu" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 1.5em; orphans: 3; widows: 3; break-after: avoid; margin-top: 1.275em; margin-bottom: 0.85em; font-weight: 700; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>new Menu()</code></h3>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>创建一个新的菜单.</p>
<h2 id="方法" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 1.75em; orphans: 3; widows: 3; break-after: avoid; margin-top: 1.275em; margin-bottom: 0.85em; font-weight: 700; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>方法</h2>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>菜单</code><span> </span>类有如下方法:</p>
<h3 id="menusetapplicationmenumenu" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 1.5em; orphans: 3; widows: 3; break-after: avoid; margin-top: 1.275em; margin-bottom: 0.85em; font-weight: 700; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>Menu.setApplicationMenu(menu)</code></h3>
<ul style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 16px; margin: 0px 0px 0.85em; padding: 0px 0px 0px 2em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><li >
<code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>menu</code><span> </span>Menu</li></ul>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>在 OS X 上设置应用菜单<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>menu</code><span> </span>. 在windows 和 linux，是为每个窗口都在其顶部设置菜单<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>menu</code>.</p>
<h3 id="menusendactiontofirstresponderaction-os-x" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 1.5em; orphans: 3; widows: 3; break-after: avoid; margin-top: 1.275em; margin-bottom: 0.85em; font-weight: 700; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>
<code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>Menu.sendActionToFirstResponder(action)</code><span> </span><em >OS X</em>
</h3>
<ul style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 16px; margin: 0px 0px 0.85em; padding: 0px 0px 0px 2em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><li >
<code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>action</code><span> </span>String</li></ul>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>发送<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>action</code><span> </span>给应用的第一个响应器.这个用来模仿 Cocoa 菜单的默认行为，通常你只需要使用<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>MenuItem</code>的属性<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>role</code>.</p>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>查看更多 OS X 的原生 action<span> </span>OS X Cocoa Event Handling Guide<span> </span>.</p>
<h3 id="menubuildfromtemplatetemplate" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 1.5em; orphans: 3; widows: 3; break-after: avoid; margin-top: 1.275em; margin-bottom: 0.85em; font-weight: 700; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>Menu.buildFromTemplate(template)</code></h3>
<ul style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 16px; margin: 0px 0px 0.85em; padding: 0px 0px 0px 2em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><li >
<code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>template</code><span> </span>Array</li></ul>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>一般来说，<code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>template</code><span> </span>只是用来创建<span> </span><a href="MENUITEM.html">MenuItem</a><span> </span>的数组<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>参数</code><span> </span>.</p>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>你也可以向<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>template</code><span> </span>元素添加其它东西，并且他们会变成已经有的菜单项的属性.</p>
<h2 id="实例方法" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 1.75em; orphans: 3; widows: 3; break-after: avoid; margin-top: 1.275em; margin-bottom: 0.85em; font-weight: 700; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>实例方法</h2>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>menu</code><span> </span>对象有如下实例方法</p>
<h3 id="menupopupbrowserwindow-x-y-positioningitem" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 1.5em; orphans: 3; widows: 3; break-after: avoid; margin-top: 1.275em; margin-bottom: 0.85em; font-weight: 700; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>menu.popup([browserWindow, x, y, positionin<a href="../../git/index.html">git</a>em])</code></h3>
<ul style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 16px; margin: 0px 0px 0.85em; padding: 0px 0px 0px 2em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>
<li >
<code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>browserWindow</code><span> </span>BrowserWindow (可选) - 默认为<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>null</code>.</li>
<li >
<code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>x</code><span> </span>Number (可选) - 默认为 -1.</li>
<li >
<code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>y</code><span> </span>Number (<strong >必须</strong><span> </span>如果x设置了) - 默认为 -1.</li>
<li >
<code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>positioningItem</code><span> </span>Number (可选)<span> </span><em >OS X</em><span> </span>- 在指定坐标鼠标位置下面的菜单项的索引. 默认为 -1.</li>
</ul>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>在<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>browserWindow</code><span> </span>中弹出 context menu .你可以选择性地提供指定的<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>x, y</code><span> </span>来设置菜单应该放在哪里,否则它将默认地放在当前鼠标的位置.</p>
<h3 id="menuappendmenuitem" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 1.5em; orphans: 3; widows: 3; break-after: avoid; margin-top: 1.275em; margin-bottom: 0.85em; font-weight: 700; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>menu.append(menuItem)</code></h3>
<ul style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 16px; margin: 0px 0px 0.85em; padding: 0px 0px 0px 2em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><li >
<code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>menuItem</code><span> </span>MenuItem</li></ul>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>添加菜单项.</p>
<h3 id="menuinsertpos-menuitem" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 1.5em; orphans: 3; widows: 3; break-after: avoid; margin-top: 1.275em; margin-bottom: 0.85em; font-weight: 700; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>menu.insert(pos, menuItem)</code></h3>
<ul style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 16px; margin: 0px 0px 0.85em; padding: 0px 0px 0px 2em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>
<li >
<code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>pos</code><span> </span>Integer</li>
<li >
<code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>menuItem</code><span> </span>MenuItem</li>
</ul>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>在制定位置添加菜单项.</p>
<h3 id="menuitems" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 1.5em; orphans: 3; widows: 3; break-after: avoid; margin-top: 1.275em; margin-bottom: 0.85em; font-weight: 700; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>menu.items()</code></h3>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>获取一个菜单项数组.</p>
<h2 id="os-x-application-上的菜单的注意事项" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 1.75em; orphans: 3; widows: 3; break-after: avoid; margin-top: 1.275em; margin-bottom: 0.85em; font-weight: 700; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>OS X Application 上的菜单的注意事项</h2>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>相对于windows 和 linux, OS X 上的应用菜单是完全不同的style，这里是一些注意事项，来让你的菜单项更原生化.</p>
<h3 id="标准菜单" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 1.5em; orphans: 3; widows: 3; break-after: avoid; margin-top: 1.275em; margin-bottom: 0.85em; font-weight: 700; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>标准菜单</h3>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>在 OS X 上，有很多系统定义的标准菜单，例如<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>Services</code><span> </span>and<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>Windows</code><span> </span>菜单.为了让你的应用更标准化，你可以为你的菜单的<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>role</code><span> </span>设置值，然后 electron 将会识别他们并且让你的菜单更标准:</p>
<ul style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 16px; margin: 0px 0px 0.85em; padding: 0px 0px 0px 2em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>
<li ><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>window</code></li>
<li ><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>help</code></li>
<li ><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>services</code></li>
</ul>
<h3 id="标准菜单项行为" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 1.5em; orphans: 3; widows: 3; break-after: avoid; margin-top: 1.275em; margin-bottom: 0.85em; font-weight: 700; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>标准菜单项行为</h3>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>OS X 为一些菜单项提供了标准的行为方法，例如<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>About xxx</code>,<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>Hide xxx</code>, and<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>Hide Others</code>. 为了让你的菜单项的行为更标准化，你应该为菜单项设置<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>role</code><span> </span>属性.</p>
<h3 id="主菜单名" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 1.5em; orphans: 3; widows: 3; break-after: avoid; margin-top: 1.275em; margin-bottom: 0.85em; font-weight: 700; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>主菜单名</h3>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>在 OS X ，无论你设置的什么标签，应用菜单的第一个菜单项的标签始终未你的应用名字.想要改变它的话，你必须通过修改应用绑定的<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>Info.plist</code><span> </span>文件来修改应用名字.更多信息参考About Information Property List Files<span> </span>.</p>
<h2 id="为制定浏览器窗口设置菜单-linux-windows" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 1.75em; orphans: 3; widows: 3; break-after: avoid; margin-top: 1.275em; margin-bottom: 0.85em; font-weight: 700; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>为制定浏览器窗口设置菜单 (<em >Linux</em><span> </span><em >Windows</em>)</h2>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>浏览器窗口的[<code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>setMenu</code><span> </span>方法][setMenu] 能够设置菜单为特定浏览器窗口的类型.</p>
<h2 id="菜单项位置" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 1.75em; orphans: 3; widows: 3; break-after: avoid; margin-top: 1.275em; margin-bottom: 0.85em; font-weight: 700; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>菜单项位置</h2>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>当通过<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>Menu.buildFromTemplate</code><span> </span>创建菜单的时候，你可以使用<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>position</code><span> </span>and<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>id</code><span> </span>来放置菜单项.</p>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>MenuItem</code><span> </span>的属性<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>position</code><span> </span>格式为<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>[placement]=[id]</code>，<code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>placement</code><span> </span>取值为<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>before</code>,<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>after</code>, 或<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>endof</code><span> </span>和<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>id</code>，<span> </span><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>id</code><span> </span>是菜单已经存在的菜单项的唯一 ID:</p>
<ul style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 16px; margin: 0px 0px 0.85em; padding: 0px 0px 0px 2em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>
<li >
<code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>before</code><span> </span>- 在对应引用id菜单项之前插入. 如果引用的菜单项不存在，则将其插在菜单末尾.</li>
<li >
<code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>after</code><span> </span>- 在对应引用id菜单项之后插入. 如果引用的菜单项不存在，则将其插在菜单末尾.</li>
<li >
<code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0.2em; margin: 0px; background-color: rgb(247, 247, 247);'>endof</code><span> </span>- 在逻辑上包含对应引用id菜单项的集合末尾插入. 如果引用的菜单项不存在, 则将使用给定的id创建一个新的集合，并且这个菜单项将插入.</li>
</ul>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>当一个菜档项插入成功了，所有的没有插入的菜单项将一个接一个地在后面插入.所以如果你想在同一个位置插入一组菜单项，只需要为这组菜单项的第一个指定位置.</p>
<h3 id="例子" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 1.5em; orphans: 3; widows: 3; break-after: avoid; margin-top: 1.275em; margin-bottom: 0.85em; font-weight: 700; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>例子</h3>
<p style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>模板:</p>
<pre style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; break-inside: avoid; direction: ltr; border: none; color: rgb(51, 51, 51); overflow: auto; word-wrap: normal; margin: 0px 0px 1.275em; padding: 0.85em 1em; background: rgb(247, 247, 247); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><code class="lang-javascript" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0px; margin: 0px; background: 0px 0px; display: inline; max-width: initial; overflow: initial; line-height: inherit; white-space: pre;'>[
  {label: <span class="hljs-string" >'4'</span>, id: <span class="hljs-string" >'4'</span>},
  {label: <span class="hljs-string" >'5'</span>, id: <span class="hljs-string" >'5'</span>},
  {label: <span class="hljs-string" >'1'</span>, id: <span class="hljs-string" >'1'</span>, position: <span class="hljs-string" >'before=4'</span>},
  {label: <span class="hljs-string" >'2'</span>, id: <span class="hljs-string" >'2'</span>},
  {label: <span class="hljs-string" >'3'</span>, id: <span class="hljs-string" >'3'</span>}
]
</code></pre>
<p style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>菜单:</p>
<pre style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; break-inside: avoid; direction: ltr; border: none; color: rgb(51, 51, 51); overflow: auto; word-wrap: normal; margin: 0px 0px 1.275em; padding: 0.85em 1em; background: rgb(247, 247, 247); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0px; margin: 0px; background: 0px 0px; display: inline; max-width: initial; overflow: initial; line-height: inherit; white-space: pre;'>- 1
- 2
- 3
- 4
- 5
</code></pre>
<p style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>模板:</p>
<pre style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; break-inside: avoid; direction: ltr; border: none; color: rgb(51, 51, 51); overflow: auto; word-wrap: normal; margin: 0px 0px 1.275em; padding: 0.85em 1em; background: rgb(247, 247, 247); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><code class="lang-javascript" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0px; margin: 0px; background: 0px 0px; display: inline; max-width: initial; overflow: initial; line-height: inherit; white-space: pre;'>[
  {label: <span class="hljs-string" >'a'</span>, position: <span class="hljs-string" >'endof=letters'</span>},
  {label: <span class="hljs-string" >'1'</span>, position: <span class="hljs-string" >'endof=numbers'</span>},
  {label: <span class="hljs-string" >'b'</span>, position: <span class="hljs-string" >'endof=letters'</span>},
  {label: <span class="hljs-string" >'2'</span>, position: <span class="hljs-string" >'endof=numbers'</span>},
  {label: <span class="hljs-string" >'c'</span>, position: <span class="hljs-string" >'endof=letters'</span>},
  {label: <span class="hljs-string" >'3'</span>, position: <span class="hljs-string" >'endof=numbers'</span>}
]
</code></pre>
<p style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0.85em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>菜单:</p>
<pre style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; break-inside: avoid; direction: ltr; border: none; color: rgb(51, 51, 51); overflow: auto; word-wrap: normal; margin: 0px 0px 1.275em; padding: 0.85em 1em; background: rgb(247, 247, 247); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;'><code style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.85em; break-inside: avoid; direction: ltr; border: none; color: inherit; padding: 0px; margin: 0px; background: 0px 0px; display: inline; max-width: initial; overflow: initial; line-height: inherit; white-space: pre;'>- ---
- a
- b
- c
- ---
- 1
- 2
- 3
</code></pre>
<p class="comments-section" style='-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: transparent; text-size-adjust: none; position: relative; font-size: 16px; orphans: 3; widows: 3; margin-top: 0px; margin-bottom: 0px !important; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.2px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;'>[setMenu]:<span> </span><a href="HTTPWWWkubijiCNELECTRONMANUALELECTRONMANUAL-BROWSER-WINDOWHTML.html">/book/electronmanual/electronmanual-browser-window.html</a></p></div>
      <div class="prev-next" style="padding:8px;">上一篇：<a class="prev" href="ELECTRONIPCMAINMoKuai.html">Electron ipcMain 模块</a><br>下一篇：<a class="prev" href="ELECTRONMENUITEMMoKuai.html">Electron MenuItem 模块</a><br></div>
    
            </div>
        </div> 
      </div>
    </div>
  </body>

<!-- Mirrored from www.dba.cn/book/electron/ZaiZhuJinChengNeiKeYongDeMoKuai/ELECTRONMENUMoKuai.html by HTTrack Website Copier/3.x [XR&CO'2014], Sun, 20 Mar 2022 10:24:11 GMT -->
</html>